<?php

namespace backend\models;

/**
 * @author  shuang
 * @date    2017-2-24 22:22:56
 * @version V1.0
 * @desc    
 */
use common\models\UserDrawalRecord;
use Yii;

class MY_UserDrawalRecord extends UserDrawalRecord {

    public static function getList() {
        $query = MY_UserDrawalRecord::find();
        $query->leftJoin(["userprofile" => MY_UserProfile::tableName()], "userprofile.userid=me_user_drawal_record.userid");
        $query->select("me_user_drawal_record.*,userprofile.username");
        $query->andFilterWhere(["like", "userprofile.username", Yii::$app->request->post("search")]);
        $query->orFilterWhere(["like", "id", Yii::$app->request->post("search")]);
        $begin_at = Yii::$app->request->post("begin_at");
        $end_at = Yii::$app->request->post("end_at");
        if ($begin_at) {
            $query->andFilterWhere([">=", "unix_timestamp(payment_time)", strtotime($begin_at)]);
        }
        if ($end_at) {
            $query->andFilterWhere(["<=", "unix_timestamp(payment_time)", strtotime($end_at)]);
        }
        $query->orderBy("me_user_drawal_record.payment_time desc");
        $countQuery = clone $query;
        $totalCount = $countQuery->count();
        $res = $query->asArray()->all();
        return ["total" => $totalCount, "data" => $res];
    }

}
